package _09volatile保证可见性;

public class Demo {
    private volatile static boolean flag=true;

    public static void main(String[] args) throws InterruptedException {

        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("线程一运行");
                while (flag){

                }
                System.out.println("线程一结束");
            }
        }).start();

        Thread.sleep(1000);

        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("线程二运行");
                flag=false;
                System.out.println("线程二结束");
            }
        }).start();

    }




}
